package yanchun.vip.springaop.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author SuYanchun
 * @since 2025-02-11 13:17
 */

/**
 * @Aspect 表示这个类是一个切面类
 * @author SuYanchun
 * @since 2025-02-11 13:17
 */
@Aspect
@Component
public class LogAspect {

    @Before("execution(public int yanchun.vip.springaop.service.MathCalculator.*(int,int))")
    public void logStart(){
        System.out.println("【log】---logStart");
    }

    @After(value = "execution(public int yanchun.vip.springaop.service.MathCalculator.*(int,int))")
    public void logEnd(JoinPoint joinPoint){
        System.out.println("【log】---logEnd 参数："+ Arrays.toString(joinPoint.getArgs()));
    }

    @AfterReturning(value = "execution(public int yanchun.vip.springaop.service.MathCalculator.*(int,int))",returning = "result")
    public void logReturn(Object result){
        System.out.println("【log】---logReturn 返回值：" + result);
    }


    @AfterThrowing("execution(public int yanchun.vip.springaop.service.MathCalculator.*(int,int))")
    public void logException(){
        System.out.println("【log】---logException");
    }
}
